﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExcelAddIn1
{
    /**
     * Abstract baseclass for an implementation of a statistical test.
     */
    abstract class Test
    {
        //Significance level
        protected double alpha = 0.05;
        //Assumed mean difference. Used only for one-sided hypothesis testing with two datasets.
        protected double assumedMeanDiff = 0.0;
        //Datasets
        protected DataContainer data;
        //The result text to add to Excel
        protected List<String> res;

        /**
         * Base method for running a test.
         */
        public abstract void RunTest();

        /**
         * Checks if the mean difference field shall be visible in the test select form.
         */
        public virtual bool EnableMeanDiffField()
        {
            return false;
        }

        /**
         * Checks if the significance level field shall be visible in the test select form.
         */
        public virtual bool EnableAlphaField()
        {
            return true;
        }

        /**
         * Returns informational text for each test to be
         * shown in the test selection window.
         */
        public abstract String GetInfo();

        /**
         * Changes the significance level.
         */
        public void SetAlpha(double alpha)
        {
            this.alpha = alpha;
        }

        /**
         * Sets the assumed mean difference. Used only for one-sided hypothesis testing with two datasets.
         */
        public void SetMeanDifference(double meanDiff)
        {
            assumedMeanDiff = meanDiff;
        }

        /**
         * Returns the result text to add to Excel.
         */
        public List<String> GetResult()
        {
            return res;
        }

        /**
         * Returns the correct Test instance based on the selection in
         * the test window. Returns null if failed to find a matching test.
         */
        public static Test GetTest(int tID, DataContainer data)
        {
            Test test = null;
            
            if (tID == 1)
            {
                test = new Test_EqualVariance(data);
            }
            else if (tID == 2)
            {
                test = new Test_T_independent_2S(data);
            }
            else if (tID == 3)
            {
                test = new Test_T_independent_1S(data);
            }
            else if (tID == 4)
            {
                test = new Test_T_dependent_2S(data);
            }
            else if (tID == 5)
            {
                test = new Test_T_dependent_1S(data);
            }
            else if (tID == 6)
            {
                test = new Test_ANOVA(data);
            }
            else if (tID == 7)
            {
                test = new Test_ChiSquare_Independence(data);
            }
            else if (tID == 8)
            {
                test = new Test_Correlation(data);
            }
            else if (tID == 9)
            {
                test = new Test_LinearRegression(data);
            }
            else if (tID == 10)
            {
                test = new Test_WilcoxonSignedRank(data);
            }
            else if (tID == 11)
            {
                test = new Test_WilcoxonSumRank(data);
            }
            else if (tID == 12)
            {
                test = new Test_KruskalWallis(data);
            }
            else if (tID == 13)
            {
                test = new Test_JarqueBera(data);
            }
            else if (tID == 14)
            {
                test = new Test_ConfidenceInterval(data);
            }
            else if (tID == 15)
            {
                test = new Test_SpearmanRankCorrelation(data);
            }
            else if (tID == 16)
            {
                test = new Forecasting_MovingAverage(data);
            }
            else if (tID == 17)
            {
                test = new Forecasting_WeightedMovingAverage(data);
            }
            else if (tID == 18)
            {
                test = new Forecasting_ExponentialSmoothing(data);
            }
            else if (tID == 19)
            {
                test = new Forecasting_ESTrendAdjustment(data);
            }
            else if (tID == 20)
            {
                test = new Test_T_SinglePopulation(data);
            }
            return test;
        }
    }
}
